package display;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.Timer;



public class LEDBar_Top extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	public static final int LEDBarSize = 12;	

	
Canvas_LEDBar myCanvas;



private static RGBColor barLEDColor[] = new RGBColor[LEDBarSize];
private static RGBColor ledOnColor[] = new RGBColor[LEDBarSize];
private static RGBColor ledOffColor[] = new RGBColor[LEDBarSize];


private RGBColor defaultColor = new RGBColor();

private static int splitPoint;

public LEDBar_Top()
{
	int counter;
	
	splitPoint=LEDBarSize;
	defaultColor.SetColor(Color.BLACK);
	
	for (counter=0;counter<barLEDColor.length;counter++)
		{
		barLEDColor[counter]=defaultColor;
		ledOnColor[counter]=defaultColor;
		ledOffColor[counter]=defaultColor;
		
		}
	
	
	buildPanel();	
	setSize(400,50);
}


private void buildPanel()
{

myCanvas =new Canvas_LEDBar(barLEDColor,Canvas_LEDBar.Orientation.HORIZONTAL);
	
myCanvas.setLocation(0,0);
myCanvas.setSize(400,50);

add(myCanvas);


	
Timer PeriodicTimer = new Timer(100,new ActionListener()
{
public void actionPerformed(ActionEvent e )
	{
	Repaint();
	}
});	
PeriodicTimer.start();
}




public void Repaint()
{
	myCanvas.paintLEDs(myCanvas.getGraphics());
	//myCanvas.repaint();	
//revalidate();	
repaint();	
//this.updateUI();

}



public static void setLEDColor(int index,RGBColor color)
{
	if ((index >=0) && (index <barLEDColor.length))
		{
		barLEDColor[index]=color;
		}
}



public static void setLEDColor(int index,short color)
{
	if ((index >=0) && (index <barLEDColor.length))
		{
		barLEDColor[index]=new RGBColor(color);
		}
}




public static void setLEDStatusColor(int LEDNumber,RGBColor newLEDOnColor,RGBColor newLEDOffColor)
{
	ledOnColor[LEDNumber]=newLEDOnColor;
	ledOffColor[LEDNumber]=newLEDOffColor;
}


public static void setLEDS(int LEDPattern)
{
int Counter;

	for (Counter=0;Counter<barLEDColor.length;Counter++)
		{
		if ((LEDPattern & (1<<Counter))>0)
			{
			barLEDColor[Counter]=ledOnColor[Counter];
			}
		else
			{
			barLEDColor[Counter]=ledOffColor[Counter];		
			}
		}
}

public static void setSplitPoint(int newSplitPoint)
{
	splitPoint=newSplitPoint;	
}





public static void setLeftValue(int newValue)
{
int Counter;

for (Counter=0;Counter<splitPoint;Counter++)
	{
	if (Counter<newValue)
		{
		barLEDColor[Counter]=ledOnColor[Counter];
		}
	else
		{
		barLEDColor[Counter]=ledOffColor[Counter];
		}
	}
//TODO Set	
}





public static void setRightValue(int newValue)
{
//TODO
}
/*
public static void SetLeftValueColor(int newValue)
{
//TODO Set	
}

public static void SetRightValueColor(int newValue)
{
//TODO
}
*/
}
